package cqut.wys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * --------神兽出没--------/
 *   ┌─┐     ┌─┐
 * ┌─┘─┴─────┘─┴─┐
 * │      ─      │
 * │  ┬─┘   └─┬  │
 * │             │
 * │      ┴      │  Code is far away from bug with the animal protecting
 * └───┐      ┌──┘  神兽保佑,代码无bug
 *     │      │
 *     │      └──────┐
 *     │             ├┐
 *     │             ┌┘
 *     └┐ ┐ ┌───┬─┐ ┌┘
 *      │ ┤ ┤   │ ┤ ┤
 *      └─┴─┘   └─┴─┘
 * ----------------------/
 *
 * @author wys
 * @date 2020/3/4
 */
@RestController
@RefreshScope
public class AutoRefreshController {

    @Autowired
    private ContextRefresher contextRefresher;

    @Value("${aa}")
    private volatile String aa;

    @GetMapping("/getAa")
    public String getAa(){
        return aa;
    }

    @GetMapping("/contextRefresher")
    public String contextRefresher(){
        new Thread(()->{
            contextRefresher.refresh();
        }).start();
        return "contextRefresher";
    }
}
